<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head>
    <title>区域管理</title>

    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-store, must-revalidate">
    <meta http-equiv="expires" content="Wed, 26 Feb 1997 08:21:57 GMT">
    <meta http-equiv="expires" content="-1">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="shortcut icon" href="/dist/img/icon.png" type="image/x-icon">
    <!-- Bootstrap 3.3.6 -->
    <link rel="stylesheet" href="/dist/plugins/bootstrap/css/bootstrap.min.css">
    <!--字体-->
    <link rel="stylesheet" href="/dist/css/font-awesome.min.css">
    <!--图标-->
    <link rel="stylesheet" href="/dist/css/ionicons.min.css">
    <!--插件样式-->
    <link href="/dist/plugins/ztree/css/zTreeStyle/zTreeStyle.css" rel="stylesheet"/>
    <!--OA主样式-->
    <link rel="stylesheet" href="/dist/css/OA.min.css?t=f63f66a9">
    <link rel="stylesheet" href="/dist/css/skins/OA-skins.min.css?t=66b457d6">
    <style>
        .roleNumberModel {
            display: none;
        }

        .provinceNumberModel {
            display: none;
        }
    </style>
</head>
<body>
<section class="content" id="app">
    <div class="oaLoad">
        <div class="loadGif" id="areaProgress"></div>
    </div>
    <div class="row">
        <div class="col-md-6">
            <div class="box-body no-padding box-border iframeH2" style="overflow: auto;background: #f7f8fa;">
                <ul class="ztree" id="ulRegion"></ul>
            </div>

        </div>
        <div class="col-md-6">
            <div class="box-body no-padding box-border iframeH2" style="overflow: auto;background: #f7f8fa;">
                <ul class="ztree" id="ulProvince"></ul>
            </div>

        </div>
        <div class="text-center">
            <button style="margin-top: 5px;" id="btnSave" class="oaBtn btn btn-sm">保存</button>
        </div>

    </div>

    <div class="roleNumberModel">
        <div class="loginDh" style="width: 600px;"><img src="/dist/img/loading/loading-spinner-blue.gif" alt=""></div>
        <table class="table-detail" style="width: 600px;">
            <tr>
                <td class="td-title" style="width: 33%;" colspan="2">标配人数:</td>
                <td class="td-title" style="width: 33%;" colspan="2">销售目标:</td>
                <td class="td-title" style="width: 34%;" colspan="2">已完成:</td>
            </tr>
            <tr>
                <td class="td-title" style="width:25%;">大区经理</td>
                <td class="td-tanZongStyle" style="width:25%;">
                    <input type="text" class="text-left " style="width: 100%; border: 0px;" id="bigManagerTargerNum">
                    <span style="color: #46A4FF;position:absolute;left:80px;top: 0;">人</span>
                </td>
                <!--<td class="td-title" style="width:25%;">大区销售目标</td>
                <td class="td-tanZongStyle" style="width:25%;">
                    <input type="text" class="text-left " style="width: 100%; border: 0px;" id="saleTargetNum">
                    <span style="color: #46A4FF;position:absolute;left:80px;top: 0;">台</span>
                </td>-->
                <td class="td-title" style="width:25%;">中/大挖销售目标</td>
                <td class="td-tanZongStyle" style="width:25%;">
                    <input type="text" class="text-left " style="width: 100%; border: 0px;" id="bigTargetNum">
                    <span style="color: #46A4FF;position:absolute;left:80px;top: 0;">台</span>
                </td>
                <td class="td-title" style="width:25%;">中/大挖已完成</td>
                <td class="td-tanZongStyle" style="width:25%;">
                    <input type="text" class="text-left " style="width: 100%; border: 0px;" id="bigFinishNum">
                    <span style="color: #46A4FF;position:absolute;left:80px;top: 0;">台</span>
                </td>
            </tr>
            <tr>
                <td class="td-title">区域经理</td>
                <td class="td-tanZongStyle">
                    <input type="text" class="text-left " style="width: 100%; border: 0px;" id="managerTargerNum">
                    <span style="color: #46A4FF;position:absolute;left:80px;top: 0;">人</span>
                </td>
                <td class="td-title" style="width:25%;">小挖销售目标</td>
                <td class="td-tanZongStyle" style="width:25%;">
                    <input type="text" class="text-left " style="width: 100%; border: 0px;" id="smallTargetNum">
                    <span style="color: #46A4FF;position:absolute;left:80px;top: 0;">台</span>
                </td>
                <td class="td-title" style="width:25%;">小挖已完成</td>
                <td class="td-tanZongStyle" style="width:25%;">
                    <input type="text" class="text-left " style="width: 100%; border: 0px;" id="smallFinishNum">
                    <span style="color: #46A4FF;position:absolute;left:80px;top: 0;">台</span>
                </td>
            </tr>
        </table>
        <div class="south no-print" style="height:50px;line-height:50px;text-align:center;">
            <input type="button" value="保存" class="btn oaBtn btn-sm" style="margin-left: 10px;" id="targetSave">
        </div>
    </div>
    <!--配置地级市区域经理标配人数-->
    <div class="provinceNumberModel">
        <div class="loginDh"><img src="/dist/img/loading/loading-spinner-blue.gif" alt=""></div>
        <table class="table-detail" style="width: 400px;">
            <tr>
                <td class="td-title" style="width: 50%;" colspan="2">标配人数:</td>
            </tr>
            <tr>
                <td class="td-title">区域经理</td>
                <td class="td-tanZongStyle">
                    <input type="text" class="text-left " style="width: 100%; border: 0px;"
                           id="provinceManagerTargerNum">
                    <span style="color: #46A4FF;position:absolute;right:10px;top: 0;">人</span>
                </td>
            </tr>
        </table>
        <div class="south no-print" style="height:62px;line-height:62px;text-align:center;">
            <input type="button" value="保存" class="btn oaBtn btn-sm" style="margin-left: 10px;" id="provinceTargetSave">
        </div>
    </div>
</section>
<div id="menu" style="width: 120px;">
    <div id="recover">
        恢复
    </div>
    <div id="remove">
        彻底删除
    </div>
</div>

<!--JQ-->
<script src="https://file.ggxqce.com/web/jquery-2.2.3.min.js"></script>
<!--插件JS-->
<script src="https://file.ggxqce.com/web/bootstrap.min.js"></script>
<!--框架已定义 JS-->
<script src="/dist/js/app_iframe.js?t=ce17d0d6"></script>
<!--oa自定义  JS-->
<script src="/dist/js/oa.js?t=2b03b7cb"></script>

<script src="https://file.ggxqce.com/web/vue.min.js"></script>
<!--ztree组件所需js-->
<script type="text/javascript" src="/dist/plugins/ztree/js/jquery.ztree.all-3.5.min.js"></script>
<script type="text/javascript" src="/dist/plugins/ztree/js/jquery.ztree.exhide-3.5.js"></script>
<script type="text/javascript" src="/dist/plugins/easyui/plugins/jquery.menu.js"></script>
<script type="text/javascript" src="/dist/plugins/easyui/plugins/jquery.parser.js"></script>
<script type="text/javascript" src="/dist/plugins/lhgdialog/lhgdialog.min.js?self=true"></script>
<script type="text/javascript">
    var selectNode = {};
    $(function () {
        $("#menu").menu({
            hideOnUnhover: false,
            onClick: function (item) {
                var node = zTreeRegion.getSelectedNodes()[0];
                switch (item.id) {
                    case "recover":
                        node.delFlag = 0;
                        $.wyui.postMethod(urlConfig.system.region.save, node, function (data) {
                            zTreeRegion.updateNode(node, true);
                            zTreeRegion.cancelSelectedNode(node);
                        });
                        break;
                    case "remove":
                        if (node.children && node.children.length > 0) {
                            alert("请先删除下级区域");
                            return;
                        }
                        $.wyui.postMethod(urlConfig.system.region.removeById, {id: node.id}, function () {
                            zTreeRegion.removeNode(node);
                        });
                        break;
                    default:
                        break;
                }
            }
        });

    });
</script>
<script type="text/javascript">
    //权限列表
    var rightOpList = [];
    $.wyui.postMethod(urlConfig.system.rightOp.getRightOpByUserId, {userId: getCurrentUser().id}, function (rightOp) {
        for (var i = 0; i < rightOp.length; i++) {
            rightOpList.push(rightOp[i].eName);
        }
        console.log()
    });

    function isShowBtn(eName) {
        if (getCurrentUser().superUser || $.inArray(eName, rightOpList) > -1) {
            return true;
        } else {
            return false;
        }
    }

    var zTreeRegion = null;
    var zTreeProvince = null;
    var zTreeRegion_callback = {
        fontCss: function (treeId, treeNode) {
            return treeNode.delFlag ? {
                color: "#cccccc",
                padding: "0 50px 0 0",
                background: "url(/statics/img/stop.png)no-repeat right center"
            } : {color: "black", padding: "0", background: ""};
        },
        showIcon: function (treeId, treeNode) {
            return treeNode.isParent;
        },
        showRemoveBtn: function (treeId, treeNode) {
//            return treeNode.type == "region" && treeNode.delFlag == 0;
            if (treeNode.type == "company") {
                return;
            }
            if (treeNode.type == "region") {
                if (isShowBtn('addCounty') && treeNode.delFlag == 0) {
                    return true;
                }
            }

        },
        showRenameBtn: function (treeId, treeNode) {

//            return treeNode.type == "region" && treeNode.delFlag == 0;
            if (treeNode.type == "company") {
                return;
            }
            if (treeNode.type == "region") {
                if (isShowBtn('addCounty') && treeNode.delFlag == 0) {
                    return true;
                }
            }
        },
        addHoverDom: function (treeId, treeNode) {
            console.log(treeNode.type)
            if (treeNode.type == "root" || treeNode.delFlag == 1) return;
            if (treeNode.type == "company") {
                if (!isShowBtn('addCity')) {
                    return true;
                }
            }
            if (treeNode.type == "region") {
                if (!isShowBtn('addCounty')) {
                    return true;
                }
            }
            var sObj = $("#" + treeNode.tId + "_span");
            if (treeNode.editNameFlag || $("#addBtn_" + treeNode.tId).length > 0) return;
            var addStr = "<span class='button add' id='addBtn_" + treeNode.tId
                + "' title='添加' onfocus='this.blur();'></span>";
            sObj.after(addStr);
            if (treeNode.type == 'region' && treeNode.isParent) {
                var addStr2 = "<span class='button configure' id='configureBtn_" + treeNode.tId
                    + "' title='配置大区销售目标、区域经理标配人数、大区经理标配人数' onfocus='this.blur();'>配置</span>";
                sObj.parent().append(addStr2);
            }
            var btn = $("#addBtn_" + treeNode.tId);
            var conBtn = $("#configureBtn_" + treeNode.tId);
            if (btn) btn.bind("click", function () {
                $.wyui.postMethod(urlConfig.system.region.save, {
                    id: '',
                    name: '新建区域',
                    parentId: treeNode.type == 'company' ? '0' : treeNode.id,
                    sortNo: treeNode.children ? treeNode.children.length : 0,
                    createUserId: getCurrentUser().id,
                    delFlag: 0,
                    companyId: treeNode.companyId
                }, function (data) {
                    var newNode = zTreeRegion.addNodes(treeNode, {
                        id: data.id,
                        name: '新建区域',
                        parentId: treeNode.type == 'company' ? '0' : treeNode.id,
                        sortNo: treeNode.children ? treeNode.children.length : 0,
                        createUserId: getCurrentUser().id,
                        delFlag: 0,
                        pId: treeNode.id,
                        type: "region",
                        dataId: data.id,
                        companyId: treeNode.companyId
                    }, true)[0];
                    zTreeRegion.updateNode(treeNode);
                    zTreeRegion.editName(newNode);
                });
                return false;
            });
            if (conBtn) conBtn.bind("click", function () {
                selectNode = treeNode;
                console.log(selectNode);
                top.$.dialog({
                    id: 'openModel',
                    content: $('.roleNumberModel').html(),
                    title: "人员及销售目标配置（" + treeNode.name + "）",
                    width: 600,
                    height: 200,
                    max: false,
                    min: false,
                    lock: true
                });
                //获取值
                $.wyui.postMethod(urlConfig.warNewspaper.bigAchievements.getListByBigAreaId, {
                    bigAreaId: selectNode.id
                }, function (data) {
                    console.log(data);
                    if (data) {
                        var data = data.records;
                        console.log(data);
                        if (data) {
//                            if(data.saleTargetNum){top.$("#saleTargetNum").val(data.saleTargetNum);}
                            if (data.bigTargetNum) {
                                top.$("#bigTargetNum").val(data.bigTargetNum);
                            }
                            if (data.smallTargetNum) {
                                top.$("#smallTargetNum").val(data.smallTargetNum);
                            }
                            if (data.managerTargerNum) {
                                top.$("#managerTargerNum").val(data.managerTargerNum);
                            }
                            if (data.managerTargerNum) {
                                top.$("#bigManagerTargerNum").val(data.bigManagerTargerNum);
                            }
                            if (data.bigFinishNum) {
                                top.$("#bigFinishNum").val(data.bigFinishNum);
                            }
                            if (data.smallFinishNum) {
                                top.$("#smallFinishNum").val(data.smallFinishNum);
                            }
                        }

                    }

                });
                return false;
            });
        },
        removeHoverDom: function (treeId, treeNode) {
            $("#addBtn_" + treeNode.tId).unbind().remove();
            $("#configureBtn_" + treeNode.tId).unbind().remove();
        },
        onClick: function (event, treeId, treeNode) {
            zTreeProvince.checkAllNodes(false);
            if (treeNode.type == "region") {
                $.wyui.postMethod(urlConfig.system.region2Province.getByRegionId, {regionId: treeNode.id}, function (list) {
                    var provinceIds = new Array();
                    for (var i = 0; i < list.length; i++) {
                        provinceIds.push(list[i].provinceId);
                    }
                    var nodes = zTreeProvince.getNodesByFilter(function (node) {
                        return $.inArray(node.id, provinceIds) > -1;
                    });
                    for (var i = 0; i < nodes.length; i++) {
                        zTreeProvince.checkNode(nodes[i], true, false, false);
                    }
                });
            }
        },
        onRightClick: function (event, treeId, treeNode) {
            if (treeNode.type == "root") return;
            if (!treeNode || treeNode.delFlag == 0) return;
            zTreeRegion.selectNode(treeNode);
            $("#menu").children().hide();
            switch (treeNode.type) {
                case "region":
                    if (treeNode.delFlag) {
                        $("#recover,#remove").show();
                    }
                default:
                    break;

            }
            $('#menu').menu('show', {
                left: event.clientX,
                top: event.clientY
            });
        },
        beforeDrag: function (treeId, treeNodes) {
            for (var i = 0, l = treeNodes.length; i < l; i++) {
                if (treeNodes[i].drag === false) {
                    return false;
                }
            }
            return true;
        },
        beforeDrop: function (treeId, treeNodes, targetNode, moveType) {

            var thisType = treeNodes[0].type;
            var toType = targetNode.type;
            if (targetNode.getParentNode().type) {
                var toPrentType = targetNode.getParentNode().type;
            }
            var toPrentType = targetNode.getParentNode().type;
            console.log(thisType, toType, toPrentType, moveType);
            if (thisType == "company") {
                return false;
            }
            return targetNode ? targetNode.drop !== false : true;
        },
        onDrop: function (event, treeId, treeNodes, targetNode, moveType, isCopy) {
            var node = treeNodes[0].getParentNode();
            console.log(treeNodes[0])
            console.log(node)
            if (treeNodes[0].parentId == "0") {
                $.wyui.postMethod(urlConfig.system.region.save, {
                    id: treeNodes[0].id,
                    companyId: node.id
                }, function (data) {
                    console.log("修改大区成功");
                    console.log(data)
                });
            } else {
                $.wyui.postMethod(urlConfig.system.region.save, {
                    id: treeNodes[0].id,
                    companyId: node.companyId,
                    parentId: node.id
                }, function (data) {
                    console.log("修改区域成功");
                    console.log(data)
                });
            }
            var newNodes = new Array()
            for (var i = 0; i < node.children.length; i++) {
                var data = node.children[i]
                newNodes.push(data.id)
            }
            var obj = {regionIds: newNodes.join(",")}
            $.wyui.postMethod(urlConfig.system.region.sort, obj, function (data) {
                console.log(data)
            });

        },
        beforeEditName: function (treeId, treeNode) {
            zTreeRegion.editName(treeNode);
            return false;
        },
        beforeRemove: function (treeId, treeNode) {
            var childrenNodes = zTreeRegion.getNodesByFilter(function (node) {
                return node.pId == treeNode.id && node.delFlag == 0;
            });
            if (childrenNodes.length > 0) {
                alert("请先删除下级区域");
                return false;
            }
            $.wyui.postMethod("/region/hasIntentionCustomer.json", {id: treeNode.id}, function (data) {
                var hasIntentionCustomer = data.hasIntentionCustomer;
                if (hasIntentionCustomer) {
                    alert("该区域下有意向客户，禁止删除");
                    return false;
                }else {
                    if (confirm("确认删除吗？")) {
                        $.wyui.postMethod(urlConfig.system.region.delById, {id: treeNode.id}, function (data) {
                            treeNode.delFlag = 1;
                            zTreeRegion.updateNode(treeNode, false);
                            zTreeRegion.cancelSelectedNode(treeNode);
                        },true);
                    }
                    return false;
                }
            },true);
            return false;
        },
        beforeRename: function (treeId, treeNode, newName, isCancel) {
            if (newName.length == 0) {
                setTimeout(function () {
                    zTreeRegion.cancelEditName();
                    alert("不能为空");
                }, 0);
            } else {
                treeNode.name = newName;
                $.wyui.postMethod(urlConfig.system.region.save, treeNode, function () {
                    zTreeRegion.cancelEditName(newName);
                    zTreeRegion.cancelSelectedNode(treeNode);
                });
            }
            return false;
        },
        onRemove: function (e, treeId, treeNode) {

        },
        onRename: function (treeId, treeNode, newName, isCancel) {

        }
    };
    var zTreeRegion_setting = {
        view: {
            fontCss: zTreeRegion_callback.fontCss,
            addHoverDom: zTreeRegion_callback.addHoverDom,
            removeHoverDom: zTreeRegion_callback.removeHoverDom,
            showIcon: zTreeRegion_callback.showIcon
        },
        data: {
            simpleData: {
                enable: true
            },
            keep: {
                parent: true
            }
        },
        callback: {
            onClick: zTreeRegion_callback.onClick,
            onRightClick: zTreeRegion_callback.onRightClick,
            beforeDrag: zTreeRegion_callback.beforeDrag,
            beforeDrop: zTreeRegion_callback.beforeDrop,
            onDrop: zTreeRegion_callback.onDrop,
            beforeEditName: zTreeRegion_callback.beforeEditName,
            beforeRemove: zTreeRegion_callback.beforeRemove,
            beforeRename: zTreeRegion_callback.beforeRename,
            onRemove: zTreeRegion_callback.onRemove,
            onRename: zTreeRegion_callback.onRename
        },
        edit: {
            enable: true,
            editNameSelectAll: true,
            removeTitle: '删除',
            renameTitle: '修改',
            showRemoveBtn: zTreeRegion_callback.showRemoveBtn,
            showRenameBtn: zTreeRegion_callback.showRenameBtn
        }
    };
    //    行政区域
    var zTreeProvince_callback = {
//        是否显示删除按钮
        showRemoveBtn: function (treeId, treeNode) {
            console.log(treeNode.type)
            if (treeNode.type == "root") {
                return;
            }
            if (treeNode.type == "province") {
                return;
            }
            if (treeNode.type == "city") {
                return true;
            }
        },
//        是否显示编辑按钮
        showRenameBtn: function (treeId, treeNode) {
            if (treeNode.type == "root") {
                return;
            }
            if (treeNode.type == "province") {
                return;
            }
            if (treeNode.type == "city") {
                return true;
            }
        },
        showIcon: function (treeId, treeNode) {
            return treeNode.isParent;
        },
        addHoverDom: function (treeId, treeNode) {
            console.log(treeNode.type)
            if (treeNode.type == "root" || treeNode.delFlag == 1) return;
            var sObj = $("#" + treeNode.tId + "_span");
            if (treeNode.editNameFlag || $("#addBtn_" + treeNode.tId).length > 0) return;
            var addStr = "<span class='button add' id='addBtn_" + treeNode.tId
                + "' title='添加' onfocus='this.blur();'></span>";
            sObj.after(addStr);
            if (treeNode.type == 'city' && treeNode.isParent) {
                var addStr2 = "<span class='button configure' id='configureBtn_" + treeNode.tId
                    + "' title='区域经理标配人数' onfocus='this.blur();'>配置</span>";
                sObj.parent().append(addStr2);
            }
            var btn = $("#addBtn_" + treeNode.tId);
            var conBtn = $("#configureBtn_" + treeNode.tId);
            if (btn) btn.bind("click", function () {
                $.wyui.postMethod(urlConfig.system.province.saveNew, {
                    id: '',
                    name: '新建区域',
                    parentId: treeNode.id,
                    sortNo: treeNode.children ? treeNode.children.length : 0,
                    delFlag: 0
                }, function (data) {
                    var newNode = zTreeProvince.addNodes(treeNode, {
                        id: data.id,
                        name: '新建区域',
                        parentId: treeNode.id,
                        sortNo: treeNode.children ? treeNode.children.length : 0,
                        delFlag: 0,
                        pId: treeNode.id,
                        type: "city",
                        dataId: data.id
                    }, true)[0];
                    zTreeProvince.updateNode(treeNode);
                    zTreeProvince.editName(newNode);
                });
                return false;
            });
            if (conBtn) conBtn.bind("click", function () {
                selectNode = treeNode;
                console.log(selectNode);
                top.$.dialog({
                    id: 'openModel',
                    content: $('.provinceNumberModel').html(),
                    title: "人员及销售目标配置（" + treeNode.name + "）",
                    width: 350,
                    height: 100,
                    max: false,
                    min: false,
                    lock: true
                });
                //获取值
                $.wyui.postMethod('/province/getTargetNumByProvinceId.json', {
                    provinceId: selectNode.id
                }, function (data) {
                    console.log(data);
                    if (data) {
                        var data = data.records;
                        console.log(data);
                        console.log(data.managerTargetNum);
                        if (data) {
                            if (data.managerTargetNum) {
                                top.$("#provinceManagerTargerNum").val(data.managerTargetNum);
                            }
                        }
                    }
                });
                return false;
            });
        },
        removeHoverDom: function (treeId, treeNode) {
            console.log(treeNode.tId)
            $("#addBtn_" + treeNode.tId).unbind().remove();
            $("#configureBtn_" + treeNode.tId).unbind().remove();
        },
        beforeEditName: function (treeId, treeNode) {
            zTreeProvince.editName(treeNode);
            return false;
        },
        beforeRemove: function (treeId, treeNode) {
            var childrenNodes = zTreeProvince.getNodesByFilter(function (node) {
                return node.pId == treeNode.id && node.delFlag == 0;
            });
            if (childrenNodes.length > 0) {
                alert("请先删除下级区域");
                return false;
            }
            if (confirm("确认删除吗？")) {
                $.wyui.postMethod(urlConfig.system.province.delById, {id: treeNode.id}, function (data) {
                    treeNode.delFlag = 1;
                    zTreeProvince.updateNode(treeNode, false);
                    zTreeProvince.cancelSelectedNode(treeNode);
                },true);
            }
            return false;

        },
        beforeRename: function (treeId, treeNode, newName, isCancel) {
            if (newName.length == 0) {
                setTimeout(function () {
                    zTreeProvince.cancelEditName();
                    alert("不能为空");
                }, 0);
            } else {
                treeNode.name = newName;
                $.wyui.postMethod(urlConfig.system.province.saveNew, treeNode, function () {
                    zTreeProvince.cancelEditName(newName);
                    zTreeProvince.cancelSelectedNode(treeNode);
                });
            }
            return false;
        },
        beforeDrag: function (treeId, treeNodes) {
            for (var i = 0, l = treeNodes.length; i < l; i++) {
                if (treeNodes[i].drag === false) {
                    return false;
                }
            }
            return true;
        },
        beforeDrop: function (treeId, treeNodes, targetNode, moveType) {
            var thisType = treeNodes[0].type;
            var toType = targetNode.type;
            if (targetNode.getParentNode().type) {
                var toPrentType = targetNode.getParentNode().type;
            }
            var toPrentType = targetNode.getParentNode().type;
            console.log(thisType, toType, toPrentType, moveType);
            if (thisType == "province") {
                return false;
            }
            return targetNode ? targetNode.drop !== false : true;
        },
        onDrop: function (event, treeId, treeNodes, targetNode, moveType, isCopy) {
            var node = treeNodes[0].getParentNode();
            console.log(treeNodes[0])
            console.log(node)
            var ProvinceNodes = new Array();
            for (var i = 0; i < node.children.length; i++) {
                var data = node.children[i];
                ProvinceNodes.push(data.id)
            }
            var obj = {provinceIds: ProvinceNodes.join(",")}
            $.wyui.postMethod(urlConfig.system.province.sort, obj, function (data) {
                console.log(data)
            });

        },
        onRemove: function (e, treeId, treeNode) {

        },
        onRename: function (treeId, treeNode, newName, isCancel) {

        }
    };
    var zTreeProvince_setting = {
        view: {
            showIcon: function (treeId, treeNode) {
                return treeNode.isParent;
            },
            addHoverDom: zTreeProvince_callback.addHoverDom,
            removeHoverDom: zTreeProvince_callback.removeHoverDom,
            fontCss: zTreeRegion_callback.fontCss
        },
        data: {
            simpleData: {
                enable: true
            },
            keep: {
                parent: true
            }
        },
        check: {
            enable: true
        },
        edit: {
            enable: true,
            editNameSelectAll: true,
            removeTitle: '删除',
            renameTitle: '修改',
            showRemoveBtn: zTreeProvince_callback.showRemoveBtn,
            showRenameBtn: zTreeProvince_callback.showRenameBtn
        },
        callback:{
            beforeEditName: zTreeProvince_callback.beforeEditName,
            beforeRemove: zTreeProvince_callback.beforeRemove,
            beforeRename: zTreeProvince_callback.beforeRename,
            onRemove: zTreeProvince_callback.onRemove,
            onRename: zTreeProvince_callback.onRename,
            beforeDrag: zTreeProvince_callback.beforeDrag,
            beforeDrop: zTreeProvince_callback.beforeDrop,
            onDrop: zTreeProvince_callback.onDrop,
        }
    };
    $(function () {

        $.wyui.postMethod(urlConfig.system.region.getTreeNodes,
            {userId: getCurrentUser().id},
            function (nodes) {
                console.log(nodes);
                zTreeRegion = $.fn.zTree.init($("#ulRegion"), zTreeRegion_setting, nodes);
            });
        //隐藏没有业务涉及到的其他省份
        $.wyui.postMethod(urlConfig.system.province.getTreeNodesNew, {}, function (nodes) {
            $.wyui.postMethod('/province/getBusProvince.json', {}, function (zsList) {
                var newList=zsList.getBusProvince;
                for(var i=0;i<nodes.length;i++){
                    if(nodes[i].parentId == '0' && newList.indexOf(nodes[i].name) == -1){
                        nodes[i].isHidden=true;
                    }else{
                        nodes[i].isHidden=false;
                    }
                }
                zTreeProvince = $.fn.zTree.init($("#ulProvince"), zTreeProvince_setting, nodes);
            })
        });
        $("#btnSave").on("click", function () {
            var regionNode = zTreeRegion.getSelectedNodes()[0];
            if (!regionNode || regionNode.type != "region") {
                alert("保存成功");
                return;
            }
            var arrProvinceIds = new Array();
            var provinceNodes = zTreeProvince.getCheckedNodes(true);
            for (var i = 0; i < provinceNodes.length; i++) {
                if (provinceNodes[i].type == "city") {
                    arrProvinceIds.push(provinceNodes[i].id)
                }
            }

            $.wyui.postMethod(urlConfig.system.region2Province.config, {
                regionId: regionNode.id,
                provinceIds: arrProvinceIds.join(",")
            }, function () {
                alert("保存成功");
            });
        });
        top.$("body").delegate("#targetSave", "click", function () {
            top.$(".loginDh").show();
            var bigAreaId = selectNode.id;
//            var saleTargetNum = top.$("#saleTargetNum").val();
            var bigTargetNum = top.$("#bigTargetNum").val();
            var smallTargetNum = top.$("#smallTargetNum").val();
            var managerTargerNum = top.$("#managerTargerNum").val();
            var bigManagerTargerNum = top.$("#bigManagerTargerNum").val();
            var bigFinishNum = top.$("#bigFinishNum").val();
            var smallFinishNum = top.$("#smallFinishNum").val();
            var bigFinish = 0;
            var smallFinish = 0;
            var totalFinishNum = 0;
            if(bigFinishNum == '' && smallFinishNum != ''){
                totalFinishNum = parseFloat(bigFinish) + parseFloat(smallFinishNum);
            }else if(bigFinishNum != '' && smallFinishNum == ''){
                totalFinishNum = parseFloat(bigFinishNum) + parseFloat(smallFinish);
            }else if(bigFinishNum == '' && smallFinishNum == ''){
                totalFinishNum = parseFloat(bigFinish) + parseFloat(smallFinish);
            }else {
                totalFinishNum = parseFloat(bigFinishNum) + parseFloat(smallFinishNum);
            }
//            var totalFinishNum = parseFloat(bigFinishNum) + parseFloat(smallFinishNum);
            $.wyui.postMethod(urlConfig.warNewspaper.bigAchievements.save, {
                bigAreaId: bigAreaId,
//                saleTargetNum:saleTargetNum,
                bigTargetNum: bigTargetNum,
                smallTargetNum: smallTargetNum,
                managerTargerNum: managerTargerNum,
                bigManagerTargerNum: bigManagerTargerNum,
                bigFinishNum: bigFinishNum,
                smallFinishNum: smallFinishNum,
                totalFinishNum:totalFinishNum,
                createUserId: getCurrentUser().id
            }, function (data) {
                $.wyui.postMethod('/bonus/updateBonusMoney.json', {}, function (data) {
                    //实时更新人员奖惩金额
                    console.log("修改奖惩成功")
                }, true);
                console.log(data);
                top.$(".loginDh").hide();
                alert("保存成功");
                top.$.dialog({id: 'openModel'}).close();
                $.wyui.postMethod('/regionAchivementsService/countCurrentMoney.json', {}, function (data) {
                    //实时更新销售绩效
                    console.log("修改销售绩效成功")
                })
            });
        })

    });

    $(function () {
        top.$("body").delegate("#provinceTargetSave", "click", function () {
            top.$(".loginDh").show();
            var provinceId = selectNode.id;
            var managerTargerNum = top.$("#provinceManagerTargerNum").val();
            $.wyui.postMethod('/province/save.json', {
                id: provinceId,
                managerTargetNum: managerTargerNum
            }, function (data) {
                console.log(data);
                top.$(".loginDh").hide();
                alert("保存成功");
                top.$.dialog({id: 'openModel'}).close();
            });
        })
    });

</script>
</body>
</html>
